version: '3.9'

services:
# Сервис для разворачивания контейнера с базой данных
  database:
    image: postgres:latest
    ports:
      - "${DB_PUBLIC_PORT}:5432"
    volumes:
      - /var/lib/postgresql/data/
    environment:
      - POSTGRES_DB=${DB_NAME}
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 5s
  
# Сервис для разворачивания контейнера с приложением
  webapi:
    build:
      context: .
      dockerfile: WeatherHistory.Api/Dockerfile
    ports:
      - "${WEBAPI_PUBLIC_PORT}:80"
    depends_on:
      database:
        condition: service_healthy
    environment:
      - DATABASE_CONNECTION_STRING=host=database;port=5432;database=${DB_NAME};username=${DB_USER};password=${DB_PASSWORD}
      - UI_URL=http://localhost:${UI_PUBLIC_PORT}
  
  # Сервис для разворачивания контейнера c UI
  web:
    build:
      context: react-app
      args:
        - REACT_APP_API_URL=${REACT_APP_API_URL}
    environment:
      - REACT_APP_API_URL=${REACT_APP_API_URL}
    ports:
      - "${UI_PUBLIC_PORT}:80"